{% extends "base.html" %}

{% block css %}
<link rel="stylesheet" href="/static/css/curator.css" />
{% endblock %}


{% block content %}
<div class="alert" style="display:none">
</div>
<br />
<br />

<h3>Instructions</h3>
<p>This feature allows you to force fetch Youtube videos for one partner at a
time. Only use this if you believe that the curation tool is currently not as
upto date as you would like. Using this force update feature allows you to
either pull new videos from the API or update existing videos.</p>
<p>Updating partners can be forced updated only if any previous tasks have been
marked COMPLETED.</p>

<br />
<br />
{% if worker %}
<table class="table">
  <tr>
    <th>Actioned By</th>
    <th>Partner</th>
    <th>Time</th>
    <th>Status</th>
  </tr>
  <tr>
    <td>{{worker.created_by}}</td>
    <td>{{worker.username}}</td>
    <td>{{worker.time_started}}</td>
    <td>{% ifequal worker.status 'PROCESSING' %}
        <div class="progress progress-striped active">
            <div class="bar" style="width: 40%;">{{worker.status}}</div>
        </div>
        {% else %}
        {{worker.status}}
        {% endifequal %}
    </td>
  </tr>
  <tr>
    <td colspan="4">
      <strong>{{worker.action}}</strong>
      {% for message in worker.report_messages %}
      <p>{{ message }}</p>
      {% endfor %}
    </td>
  </tr>
</table>
{% endif %}
<br /><br /><br />

<form action="/manual_partner_update" onsubmit="return manualPartnerUpdateForm(this)" id="partnerUpdateForm" class="form-horizontal" method="POST" >
<fieldset>
    <div class="control-group">
      <label for="multiSelect" class="control-label">Associate Partners</label>
      <div class="controls">
        <select name="partner">
        {% for uploaders in partners %}
        <option value="{{uploaders}}">{{uploaders}}</option>
        {% endfor %}
        </select>
      </div>
    </div>
    <label for="multiSelect" class="control-label">Process Type</label>
      <div class="controls">
        <select name="action_type">
          <option value="INSERT">Find New Videos</option>
          <option value="UPDATE">Update Existing Videos</option>
        </select>
      </div>
<div class="form-actions">
     <input class="btn btn-primary" value="Perform Manual Update" type="submit"/>
    </div>
</fieldset>
</form>

<script>
  function manualPartnerUpdateForm(form){
    $.ajax({
      url: form.action,
      type: form.method,
      dataType: "json",
      data: $("#partnerUpdateForm").serialize(),
      success: function(message) {
        $(".alert").html(message['message']);
        $(".alert").css("display","block");
      },
    });
    return false;
  }

</script>
{% endblock %}
